package com.ruoyi.memo.service.impl;

import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.memo.mapper.CountdownMapper;
import com.ruoyi.memo.domain.Countdown;
import com.ruoyi.memo.service.ICountdownService;

/**
 * 倒计时Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-06-19
 */
@Service
public class CountdownServiceImpl implements ICountdownService 
{
    @Autowired
    private CountdownMapper countdownMapper;

    /**
     * 查询倒计时
     * 
     * @param id 倒计时主键
     * @return 倒计时
     */
    @Override
    public Countdown selectCountdownById(Long id)
    {
        return countdownMapper.selectCountdownById(id);
    }

    /**
     * 查询倒计时列表
     * 
     * @param countdown 倒计时
     * @return 倒计时
     */
    @Override
    public List<Countdown> selectCountdownList(Countdown countdown)
    {
        return countdownMapper.selectCountdownList(countdown);
    }

    /**
     * 新增倒计时
     * 
     * @param countdown 倒计时
     * @return 结果
     */
    @Override
    public int insertCountdown(Countdown countdown)
    {
        //转成int
        String timeStr = "01:30:00";
        LocalTime time = LocalTime.parse(timeStr, DateTimeFormatter.ISO_LOCAL_TIME);
        long totalSeconds = time.toSecondOfDay(); // 5400 秒
        if (totalSeconds<=0){
            return 0;
        }
//        throw new RuntimeException("倒计时必须大于0秒");
        countdown.setCreateTime(DateUtils.getNowDate());
        return countdownMapper.insertCountdown(countdown);
    }

    /**
     * 修改倒计时
     * 
     * @param countdown 倒计时
     * @return 结果
     */
    @Override
    public int updateCountdown(Countdown countdown)
    {
        countdown.setUpdateTime(DateUtils.getNowDate());
        return countdownMapper.updateCountdown(countdown);
    }

    /**
     * 批量删除倒计时
     * 
     * @param ids 需要删除的倒计时主键
     * @return 结果
     */
    @Override
    public int deleteCountdownByIds(Long[] ids)
    {
        return countdownMapper.deleteCountdownByIds(ids);
    }

    /**
     * 删除倒计时信息
     * 
     * @param id 倒计时主键
     * @return 结果
     */
    @Override
    public int deleteCountdownById(Long id)
    {
        return countdownMapper.deleteCountdownById(id);
    }
}
